<!DOCTYPE html>
<html>

<head lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <meta name="description" content="58新媒体">
    <meta name="keywords" content="58新媒体"/>
    <title>58新媒体-添加商品</title>
    <link href="../images/web.ico" rel="icon">
    <link href="../lib/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="../lib/bootstrap/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="../css/style.css" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../css/sweetalert.css">
    <link rel="stylesheet" type="text/css" href="../plugins/weui/css/jquery-weui.css"/>
    <link rel="stylesheet" type="text/css" href="../plugins/weui/css/weui.min.css"/>
    <link href="../plugins/validator/css/bootstrapValidator.min.css" rel="stylesheet">
    <link href="../plugins/validator/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
    <!---让IE9以下浏览器支持响应式布局---->
    <!--[if lt IE 9]>
    <script src="../plugins/ie/html5shiv-3.7.0.js"></script>
    <script src="../plugins/ie/respond-1.3.0.min.js"></script>
    <![endif]-->
    <style>
        img {
            max-width: 100%;
        }
        #Specifications .control-label{
            margin: 0;
            padding: 0;
        }
    </style>
</head>

<body>
<!--加载--->
<div class="loading-container">
    <div class="sk-spinner sk-spinner-wave">
        <div class="sk-rect1"></div>
        <!--此注释用于消除‘display: inline-block;’布局下标签自动生成的空白边距，请勿删除
    -->
        <div class="sk-rect2"></div>
        <!--
    -->
        <div class="sk-rect3"></div>
        <!--
    -->
        <div class="sk-rect4"></div>
        <!--
    -->
        <div class="sk-rect5"></div>
    </div>
</div>
<!--导航-->
<div class="navbar navbar-inner">
    <div class="container-fluid">
        <div class="">
            <a class="navbar-header pull-left logo" href="../../index.html">
                58新媒体管理平台
            </a>
            <div class="sidebar-collaps" id="sidebar-collapse" style="display: inline-block">
                <i class="collapse-icon glyphicon glyphicon-align-justify"></i>
            </div>
            <ul class="nav navbar-nav navbar-right navbar-custom-menu">
                <li class="dropdown">
                    <a href="#" title="警告"><i class="fa fa-exclamation-triangle"></i></a>
                </li>
                <li class="dropdown messages-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false" title="邮件"><i class="fa fa-envelope-o"></i><span
                            class="label label-success badge-s">4</span></a>
                    <ul class="dropdown-menu">
                        <li class="header">你有4封未读邮件</li>
                        <li>
                            <div class="slimScrollDiv">
                                <ul class="menu">
                                    <li>
                                        <a href="#">
                                            <div class="pull-left"><img src="../images/head-portrait/0.jpg"
                                                                        class="img-circle"></div>
                                            <h4>五大新型Python框架！
                                                <small>两小时前</small>
                                            </h4>
                                            <p>
                                                更快、更简单，更“Python化”——这就是Python生态系统中各类新型Web框架的终极诉求。在今天的文章中，我们将介绍五款面向Python的新型Web与网络框架，它能够切实提升速度表现、充分发挥突破性新特性，同时带来实现新思路的更多可行途径。</p>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#">
                                            <div class="pull-left"><img src="../images/head-portrait/4.jpg"
                                                                        class="img-circle"></div>
                                            <h4>从传统架构到云上数据
                                                <small>昨天</small>
                                            </h4>
                                            <p>
                                                从传统的架构到云上大数据，实现了很多的转变。传统的大数据平台计算和数据一般都在一起，到云上之后计算有可能是虚拟机、有可能是容器，存储和计算是分离的。任何计算节点访问存储时都是通过高速互联网络把数据迁移到本地来。</p>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#">
                                            <div class="pull-left"><img src="../images/head-portrait/2.jpg"
                                                                        class="img-circle"></div>
                                            <h4>Windows常见故障
                                                <small>昨天</small>
                                            </h4>
                                            <p>
                                                任何使用Windows系统的用户都碰到过各种各样的问题，其中一些次要的问题不但会引起你的烦恼，还会给你的工作效率带来负面影响。而那些主要的问题则可能会导致你的程序崩溃，且让你需要重新启动系统。</p>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#">
                                            <div class="pull-left"><img src="../images/head-portrait/3.jpg"
                                                                        class="img-circle"></div>
                                            <h4>移动应用开发从何入手？
                                                <small>昨天</small>
                                            </h4>
                                            <p>
                                                移动应用的开发方式多种多样。虽然从技术层面了解混合与原生应用间的区别非常重要，但更重要的仍然是立足业务层面思考具体决策会给开发团队及客户带来哪些影响。事实上，混合与原生之争久已有之，且双方在使用体验、技术、投资回报以及业务影响等层面皆各擅胜场。</p>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </li>
                        <li class="footer">
                            <a href="#">查看所有邮件</a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown messages-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false" title="通知"><i class="fa fa-bell-o"></i><span
                            class="label label-warning badge-s">10</span></a>
                    <ul class="dropdown-menu">
                        <li class="header">你有10条新消息</li>
                        <li>
                            <div class="slimScrollDiv">
                                <ul class="menu">
                                    <li>
                                        <a href="#">
                                            <i class="fa fa-user-circle-o text-yellow"></i>管理员发布了新公告
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#">
                                            <i class="fa fa-user-o text-red"></i>您有3次登录失败的记录
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#">
                                            <i class="fa fa-user-o text-info"></i>Wihend刚刚成为了超级会员
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#">
                                            <i class="fa fa-group text-aqua"></i>新同事向您发出邀请
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#">
                                            <i class="fa fa-group text-green"></i>有新员工加入
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </li>
                        <li class="footer">
                            <a href="#">查看所有消息</a>
                        </li>
                    </ul>
                </li>

                <li class="dropdown messages-menu">
                    <a href="#" class="dropdown-toggle animation-info" data-toggle="dropdown" role="button"
                       aria-haspopup="true" aria-expanded="false" title="消息"><i class="fa fa-commenting"></i></a>
                    <ul class="dropdown-menu">
                        <li class="header">有2位联系人给你发来了消息</li>
                        <li>
                            <div class="slimScrollDiv">
                                <ul class="menu">
                                    <li>
                                        <a href="#">
                                            <div class="pull-left"><img src="../images/head-portrait/0.jpg"
                                                                        class="img-circle"></div>
                                            <p>Divyia</p>
                                            <h5>在线
                                                <small>1小时前</small>
                                            </h5>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#">
                                            <div class="pull-left"><img src="../images/head-portrait/4.jpg"
                                                                        class="img-circle"></div>
                                            <p>Johnson</p>
                                            <h5>在线
                                                <small>3小时前</small>
                                            </h5>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </li>
                    </ul>
                </li>
                <li class="dropdown messages-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false"><img src="../images/head-portrait/3.jpg" class="user-img"><span
                            class="hedden-xs"> 欢迎您，Admin</span></a>
                    <ul class="dropdown-menu user-box">
                        <li class="user-header">
                            <img src="../images/head-portrait/3.jpg" class="img-circle" height="90">
                            <!--<p>WenQian-Web前端开发者<small>2014/04-至今</small></p>-->
                        </li>
                        <li class="user-footer">
                            <div class="pull-right">
                                <a class="btn btn-default" href="../html/login.html">退出</a>
                            </div>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container-fluid -->
</div>

<!--主体-->
<div class="main-container container-fluid">
    <div class="page-container" style="">
        <div class="page-sidebar">
            <div class="sidebar-header-wrapper">
                <div class="form-group has-group has-transparent">
                    <input type="text" class="form-control searchinput">
                    <div class="searchhelper">搜索报告、图表、电子邮件或通知</div>
                    <span class="fa fa-search has-group-feedback"></span>
                </div>
            </div>
            <ul class="nav sidebar-menu">
                <!--首页-->
                <li class="">
                    <a href="index.html">
                        <i class="glyphicon glyphicon-home menu-icon"></i>
                        <span class="menu-text"> 首页 </span>
                    </a>
                </li>
                <li class="">
                    <a href="member.html">
                        <i class="glyphicon menu-icon fa fa-user-circle"></i>
                        <span class="menu-text"> 用户管理 </span>
                    </a>
                </li>
                <li>
                    <a href="#" class="menu-dropdown">
                        <i class="glyphicon menu-icon fa fa-newspaper-o"></i>
                        <span class="menu-text"> 新闻中心 </span>
                        <i class="fa fa-angle-left menu-expand"></i>
                    </a>
                    <ul class="submenu">
                        <li>
                            <a href="news-classification.html">
                                <span class="menu-text">新闻分类</span>
                            </a>
                        </li>
                        <li>
                            <a href="news.html">
                                <span class="menu-text">新闻中心</span>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="">
                    <a href="#" class="menu-dropdown">
                        <i class="glyphicon menu-icon fa fa-video-camera"></i>
                        <span class="menu-text"> 视频中心 </span>
                        <i class="fa fa-angle-left menu-expand"></i>
                    </a>
                    <ul class="submenu">
                        <li class="">
                            <a href="video-classification.html">
                                <span class="menu-text">视频分类</span>
                            </a>
                        </li>
                        <li class="">
                            <a href="video.html">
                                <span class="menu-text">视频中心</span>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="active open">
                    <a href="#" class="menu-dropdown">
                        <i class="glyphicon menu-icon fa fa-shopping-cart"></i>
                        <span class="menu-text"> 商品中心 </span>
                        <i class="fa fa-angle-left menu-expand"></i>
                    </a>
                    <ul class="submenu">
                        <li>
                            <a href="shop-classification.html">
                                <span class="menu-text">商品分类</span>
                            </a>
                        </li>
                        <li class="active">
                            <a href="shop.html">
                                <span class="menu-text">商品列表</span>
                            </a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a href="forward.html">
                        <i class="glyphicon menu-icon fa fa-file-text-o"></i>
                        <span class="menu-text"> 提现打款 </span>
                    </a>
                </li>
                <li class="">
                    <a href="transfer.html">
                        <i class="glyphicon menu-icon fa fa-file-text-o"></i>
                        <span class="menu-text"> 转账 </span>
                    </a>
                </li>
                <li>
                    <a href="order.html">
                        <i class="glyphicon menu-icon fa fa-server menu-icon"></i>
                        <span class="menu-text"> 订单管理 </span>
                    </a>
                </li>
                <li>
                    <a href="#" class="menu-dropdown">
                        <i class="glyphicon menu-icon fa fa-calendar-minus-o"></i>
                        <span class="menu-text"> 任务管理 </span>
                        <i class="fa fa-angle-left menu-expand"></i>
                    </a>
                    <ul class="submenu">
                        <li>
                            <a href="taskType.html">
                                <span class="menu-text">任务类型</span>
                            </a>
                        </li>
                        <li>
                            <a href="taskScreenshots.html">
                                <span class="menu-text">任务截图</span>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="">
                    <a href="#" class="menu-dropdown">
                        <i class="glyphicon menu-icon fa fa-window-restore"></i>
                        <span class="menu-text"> 套餐 </span>
                        <i class="fa fa-angle-left menu-expand"></i>
                    </a>
                    <ul class="submenu">
                        <li class="">
                            <a href="meal-list.html">
                                <span class="menu-text">套餐列表</span>
                            </a>
                        </li>
                        <li class="">
                            <a href="meal-detailed.html">
                                <span class="menu-text">套餐明细</span>
                            </a>
                        </li>
                        <li class="">
                            <a href="meal-run.html">
                                <span class="menu-text">套餐管理</span>
                            </a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a href="signIn.html">
                        <i class="glyphicon menu-icon fa fa-map-marker"></i>
                        <span class="menu-text"> 签到明细 </span>
                    </a>
                </li>
                <li>
                    <a href="read.html">
                        <i class="glyphicon menu-icon fa fa-book"></i>
                        <span class="menu-text"> 阅读赚钱明细 </span>
                    </a>
                </li>
                <li>
                    <a href="distribution-commission.html">
                        <i class="glyphicon menu-icon fa fa-mail-forward"></i>
                        <span class="menu-text"> 分销佣金明细 </span>
                    </a>
                </li>
                <li class="">
                    <a href="InvitationToEarn.html">
                        <i class="glyphicon menu-icon fa fa-id-badge"></i>
                        <span class="menu-text"> 邀请赚取 </span>
                    </a>
                </li>
                <li class="">
                    <a href="notice.html">
                        <i class="glyphicon menu-icon fa fa-bullhorn menu-icon"></i>
                        <span class="menu-text"> 系统公告 </span>
                    </a>
                </li>
                <li class="">
                    <a href="store-detailed.html">
                        <i class="glyphicon menu-icon fa fa-mail-forward"></i>
                        <span class="menu-text"> 商城分销明细 </span>
                    </a>
                </li>
                <!--<li class="">
                    <a href="quotaDetails.html">
                        <i class="glyphicon menu-icon fa fa-sort-amount-desc"></i>
                        <span class="menu-text"> 额度明细 </span>
                    </a>
                </li>-->
            </ul>
        </div>

        <!---page-sidebar--->

        <div class="page-wrapper">
            <div class="page-breadcrumbs">
                <ol class="breadcrumb">
                    <li><i class="fa fa-home"></i>
                        <a href="index.html">首页</a>
                    </li>
                    <li>添加商品</li>
                </ol>
            </div>
            <div class="page-header position-relative">
                <div class="header-title title-h1">添加商品</div>
            </div>

            <div class="page-body">
                <!--基本表单--->
                <div class="row">
                    <!--基本表单--->
                    <div class="col-lg-12">
                        <div class="widget">
                            <div class="widget-header">
                                <div class="widget-caption">添加商品</div>
                            </div>
                            <div class="widget-body">
                                <form id="defaultForm" method="post" class="form-horizontal" action="">
                                    <input type="hidden" id="id" name="id"/>
                                    <input type="hidden" name="userId" id="userId" value="0"/>
                                    <div class="form-group">
                                        <label class="col-lg-3 control-label">商品名称:<i class="red">*</i></label>
                                        <div class="col-lg-5">
                                            <input type="text" class="form-control" name="tradeName" id="tradeName"
                                                   placeholder="商品名称"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-3 control-label">商品首图:<i class="red">*</i></label>
                                        <div class="col-lg-5">
                                            <div class="weui-uploader__bd">
                                                <div class="weui-uploader__bd">
                                                    <ul class="weui-uploader__files" id="uploaderFiles">

                                                    </ul>
                                                    <div class="weui-uploader__input-box">
                                                        <input id="uploaderInput"
                                                               class="weui-uploader__input zjxfjs_file"
                                                               name="multipartFile" type="file" accept="image/*"
                                                               multiple="" onchange="previewImage(this)">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-3 control-label">所属商品分类:<i class="red">*</i></label>
                                        <div class="col-lg-5">
                                            <select class="form-control" id="commodityClassification"
                                                    name="classificationId">
                                                <option value="">---请选择---</option>
                                            </select>
                                        </div>
                                    </div>
                                    <!--<div class="form-group">
                                        <label for="inputEmail2" class="col-sm-3 control-label">编写时间：</label>
                                        <div class="col-sm-5 form_datetime date" data-date-format="yyyy-mm-dd hh:ii:ss">
                                            <input type="text" class="form-control" name="writingTime" id="inputEmail2"
                                                   placeholder="编写时间" readonly="readonly">
                                        </div>
                                    </div>-->
                                    <div class="form-group">
                                        <label class="col-lg-3 control-label">商品简介:<i class="red">*</i></label>
                                        <div class="col-lg-5">
                                            <input type="text" class="form-control" name="productBrief"
                                                   id="productBrief"
                                                   placeholder="商品简介"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-3 control-label">原商品链接:<i class="red">*</i></label>
                                        <div class="col-lg-5">
                                            <input type="text" class="form-control" name="commodityLink"
                                                   id="commodityLink"
                                                   placeholder="原商品链接"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-3 control-label">商品价格:<i class="red">*</i></label>
                                        <div class="col-lg-5">
                                            <input type="text" class="form-control" name="commodityPrice"
                                                   id="commodityPrice"
                                                   placeholder="商品价格"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-3 control-label">阅读宝数量:<i class="red">*</i></label>
                                        <div class="col-lg-5">
                                            <input type="text" class="form-control" name="commodityReadingTreasure"
                                                   id="commodityReadingTreasure"
                                                   placeholder="阅读宝数量"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-3 control-label">商品库存:<i class="red">*</i></label>
                                        <div class="col-lg-5">
                                            <input type="text" class="form-control" name="commodityInventory"
                                                   id="commodityInventory"
                                                   placeholder="商品库存"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">是否是会员产品:<i class="red">*</i></label>
                                        <div class="col-lg-5">
                                            <label class="radio radio-inline">
                                                <input type="radio" name="designatedProduct" value="是" required
                                                       data-bv-notempty-message="请选择"/>
                                                <span class="text">是</span>
                                            </label>
                                            <label class="radio radio-inline">
                                                <input type="radio" name="designatedProduct" value="否" checked/>
                                                <span class="text">否</span>
                                            </label>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">介绍:<i class="red">*</i></label>
                                        <div class="col-lg-5">
                                            <!-- 加载编辑器的容器 -->
                                            <textarea id="editor" name="commodityDetails" type="text/plain"></textarea>
                                        </div>
                                    </div>
                                    <div class="" id="Specifications">
                                        <div class="form-group">
                                            <label class="col-lg-2 control-label">产品规格：</label>
                                            <div class="col-lg-8">
                                                <label class="col-lg-2 control-label">规格名称：</label>
                                                <div class="col-lg-3">
                                                    <input type="text" class="form-control specificationNames"
                                                           id="index1specificationNames" placeholder="规格名称"/>
                                                </div>
                                                <label class="col-lg-2 control-label">阅读宝数量：</label>
                                                <div class="col-lg-2">
                                                    <input type="text" class="form-control prices" placeholder="阅读宝数量"
                                                           id="index1prices" value="0"
                                                           onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')"/>
                                                </div>
                                                <label class="col-lg-1 control-label">现金：</label>
                                                <div class="col-lg-2">
                                                    <input type="text" class="form-control cash" placeholder="现金"
                                                           id="index1cash" value="0"
                                                           onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')"/>
                                                </div>
                                            </div>
                                            <div class="col-lg-2 col-sm-2 col-xs-2">
                                                <button type="button" class="btn btn-default btn-sm addButton"
                                                        data-template="name">增加内容
                                                </button>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="col-lg-9 col-lg-offset-3">
                                            <button type="button" class="btn btn-primary" id="validateBtn" name="signup"
                                                    value="提交" data-loading-text="上传中请稍后...">提交
                                            </button>
                                            <button type="reset" class="btn btn-info" id="resetBtn">重置</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>

        </div>
        <!--page-wrapper--->

    </div>
</div>
<!--回到顶部--->
<a id="backTop">
    <i class="fa fa-angle-up"></i>
</a>

<script src="../lib/jquery/jquery.min.js" type="text/javascript"></script>
<script src="../lib/bootstrap/js/bootstrap.min.js"></script>
<script src="../plugins/validator/js/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../js/sweetalert-dev.js"></script>
<script src="../js/desc.js"></script>
<script type="text/javascript" src="../js/public.js"></script>
<script type="text/javascript" src="../js/form-edit.js"></script>
<script src="../plugins/validator/js/bootstrap-datetimepicker.min.js"></script>
<script src="../plugins/validator/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="../plugins/weui/js/jquery-weui.js" type="text/javascript" charset="utf-8"></script>

<!-- 配置文件 -->
<script type="text/javascript" src="../plugins/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="../plugins/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('editor');
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function (action) {
        console.log("action:" + action)
        if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
            console.log("upload")
            return 'http://news.whilte.com/upload';
        } else if (action == 'listimage') {
            return this._bkGetActionUrl.call(this, action);
        } else {
            return this._bkGetActionUrl.call(this, action);
        }

    };

    // 获取url中的参数
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        } else {
            return null;
        }
    }

    var key = 0;
    $(function () {
        //获取url中的targetId参数
        var id = getUrlParam('id');
        if (id != null) {
            findById();
            queryCommodityId();
        } else {
            querytype();
        }


        function findById() {
            $('#id').val(id);
            $.ajax({
                url: website + "/CommodityController/findById",
                type: "POST",
                data: {'id': id},
                success: function (data) {
                    $("#uploaderFiles").append('<li class="weui-uploader__file" onclick="removeimgs(this)" style="background-image:url(' + data.data.commodity.encryptedName + ')"></li>');
                    $("#tradeName").val(data.data.commodity.tradeName);
                    $("#productBrief").val(data.data.commodity.productBrief);
                    $("#commodityPrice").val(data.data.commodity.commodityPrice);
                    $("#commodityInventory").val(data.data.commodity.commodityInventory);
                    $("#commodityLink").val(data.data.commodity.commodityLink);
                    if (data.data.commodity.commodityReadingTreasure == '' || data.data.commodity.commodityReadingTreasure == null) {
                        $("#commodityReadingTreasure").val('0');
                    } else {
                        $("#commodityReadingTreasure").val(data.data.commodity.commodityReadingTreasure);
                    }
                    if (data.data.commodity.designatedProduct == "是") {
                        $(":radio[name='designatedProduct'][value='是']").prop("checked", "checked");
                    } else {
                        $(":radio[name='designatedProduct'][value='否']").prop("checked", "checked");
                    }

                    if (data.data.commodity.commodityClassification == null) {
                        query();
                    } else {
                        key = data.data.commodity.commodityClassification.id;
                        query();
                    }


                    if (data.data.commodity.user == null) {
                        $("#userId").val(0);
                    } else {
                        $("#userId").val(data.data.commodity.user.id);
                    }

                    var cont = data.data.commodity.commodityDetails;
                    ue.ready(function () {
                        ue.setContent(cont);
                    });
                },
            });

        }

        function queryCommodityId() {
            var html = '';
            $.ajax({
                url: website + "/CommoditySpecificationController/queryCommodityId",
                type: "POST",
                data: {'commodityId': id},
                success: function (data) {
                    // index1specificationNames   index1prices
                    data.data.forEach(function (value,i) {
                        if (i == 0) {
                            $("#index1specificationNames").val(value.specification_name);
                            if(value.commodity_price!=null){
                                $("#index1prices").val(value.commodity_price);
                            }else{
                                $("#index1prices").val('0');
                            }
                            if(value.cash!=null){
                                $("#index1cash").val(value.cash);
                            }else{
                                $("#index1cash").val('0');
                            }

                        } else {
                            html+='<div class="">\n' +
                            '                                        <div class="form-group">\n' +
                            '                                            <label class="col-lg-2 control-label">产品规格：</label>\n' +
                            '                                            <div class="col-lg-8">\n' +
                            '                                                    <label class="col-lg-2 control-label">规格名称：</label>\n' +
                            '                                                    <div class="col-lg-3">\n' +
                            '                                                        <input type="text" class="form-control specificationNames" value="'+value.specification_name+'" placeholder="规格名称"/>\n' +
                            '                                                    </div>\n'+
                            '                                                    <label class="col-lg-2 control-label">阅读宝数量：</label>\n' +
                            '                                                    <div class="col-lg-2">\n';
                            if(value.commodity_price!=null){
                                html+='<input type="text" class="form-control prices" value="'+value.commodity_price+'" placeholder="阅读宝数量" onkeyup="value=value.replace(/[^\\d{1,}\\.\\d{1,}|\\d{1,}]/g,\'\')"/>\n';
                            }else{
                                html+='<input type="text" class="form-control prices" value="0" placeholder="阅读宝数量" onkeyup="value=value.replace(/[^\\d{1,}\\.\\d{1,}|\\d{1,}]/g,\'\')"/>\n';
                            }
                            html+='                                                    </div>\n' +
                            '                                                    <label class="col-lg-1 control-label">现金：</label>\n' +
                            '                                                    <div class="col-lg-2">\n';
                            if(value.cash!=null){
                                html+='<input type="text" class="form-control cash" value="'+value.cash+'" placeholder="现金" onkeyup="value=value.replace(/[^\\d{1,}\\.\\d{1,}|\\d{1,}]/g,\'\')"/>\n';
                            }else{
                                html+='<input type="text" class="form-control cash" value="0" placeholder="现金" onkeyup="value=value.replace(/[^\\d{1,}\\.\\d{1,}|\\d{1,}]/g,\'\')"/>\n';
                            }
                            html+='                                                    </div>\n' +
                            '                                            </div>\n' +
                            '                                            <div class="col-lg-2 col-sm-2 col-xs-2"><button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-default btn-sm removeButton">删除</button></div>'+
                            '                                        </div>\n' +
                            '                                    </div>';
                        }
                    })
                    $("#Specifications").append(html);
                },
            });


        }

        function query() {
            $.ajax({
                url: website + "/CommodityClassificationController/queryAll1",
                type: "POST",
                processData: false,
                success: function (data) {
                    var options = [];
                    data.data.forEach(function (obj) {
                        if (obj.id === key) {
                            options.push('<option value="' + obj.id + '" selected>' + obj.classificationName + '</option>');
                        } else {
                            options.push('<option value="' + obj.id + '">' + obj.classificationName + '</option>');
                        }

                    })
                    $('#commodityClassification').append(options);
                },
            });
        }

    });

    var checked = false;
    $('body').on('change', '#specifications', function () {
        checked = this.checked ? "true" : "false";
        if (checked == true) {

        }
    });


    var thisun = "";
    $(document).on("click", ".removeButton", function () {
        thisun = this;
        swal({
            title: "您确定要删除吗?",
            text: "确认删除?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确认删除",
            closeOnConfirm: false
        }, function () {
            swal({
                title: '删除成功',
                type: "success"
            }, function () {
                updatelist(thisun);
            });
        });
    });

    $(document).ready(function () {

        // Generate a simple captcha
        function randomNumber(min, max) {
            return Math.floor(Math.random() * (max - min + 1) + min);
        };
        $('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));

        $('#defaultForm').bootstrapValidator({
            //        live: 'disabled',
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                tradeName: {
                    message: '无效',
                    validators: {
                        notEmpty: {
                            message: '请输入'
                        },
                    }
                },
                commodityClassification: {
                    validators: {
                        notEmpty: {
                            message: '请选择所属商品分类:'
                        },
                    },
                },
                productBrief: {
                    message: '无效',
                    validators: {
                        notEmpty: {
                            message: '请输入商品简介'
                        },
                    }
                },
                prices: {
                    message: '无效',
                    validators: {
                        number: {
                            message: '只能为数字'
                        },
                        greaterThan: {
                            message: '请输入合法价格'
                        },
                        notEmpty: {
                            message: '请输入商品价格'
                        },
                    }
                },
                commodityPrice: {
                    message: '无效',
                    validators: {
                        number: {
                            message: '只能为数字'
                        },
                        greaterThan: {
                            message: '请输入合法价格'
                        },
                        notEmpty: {
                            message: '请输入商品价格'
                        },
                    }
                },
                commodityReadingTreasure: {
                    message: '无效',
                    validators: {
                        digits: {
                            message: '只能为数子'
                        }
                    }
                },
                commodityInventory: {
                    message: '无效',
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        },
                        digits: {
                            message: '只能为数子'
                        }
                    }
                },

            }
        });


        // 事件事件
        $("#inputEmail2").datetimepicker({
            language: 'zh-CN',
            weekStart: 1,
            todayBtn: 1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 0,
            minuteStep: 1,
            format: 'yyyy-mm-dd hh:ii:ss',
            forceParse: 0
        });

        $('#validateBtn').click(function () {
            $('#defaultForm').data('bootstrapValidator').validate();
            var id = $('#id').val();
            if (!$('#defaultForm').data('bootstrapValidator').isValid()) { //判断校检是否通过
                swal({
                    title: "验证不通过",
                    type: "warning"
                });

                return;
            }
            if ($("#uploaderFiles li").length == 0) {
                swal({
                    title: "请选择需要上传的图片",
                    type: "warning"
                });
                return;
            } else if ($("#inputEmail2").val() == '') {
                swal({
                    title: "请选择编写时间",
                    type: "warning"
                });
                return;
            }


            var specificationNames = new Array();
            var prices = new Array();
            var cash = new Array();
            $('#Specifications .form-group').each(function (i) {
                specificationNames[i] = $(this).children("div").children("div").children(".specificationNames").val();
                prices[i] = $(this).children("div").children("div").children(".prices").val();
                cash[i]=$(this).children("div").children("div").children(".cash").val();

            });

            var specificationNamesst = true;
            var pricesst = true;
            var cashst=true;
            specificationNames.forEach(function (value) {
                if (value == null || '' == value || value== undefined) {
                    specificationNamesst = false;
                }
            });
            prices.forEach(function (value) {
                if (value == null || value == '') {
                    pricesst = false;
                }
            });
            cash.forEach(function (value) {
                if (value == null || '' == value ) {
                    cashst = false;
                }
            });

            if (specificationNamesst == false) {
                swal({
                    title: "商品规格名称不能为空",
                    type: "warning"
                });
                return;
            } else if (pricesst == false && cashst == false) {
                swal({
                    title: "阅读宝数量和现金都不能为空，可设置为0",
                    type: "warning"
                });
                return;
            }

            if (id !== null && "" !== id) {
                update();
            } else {
                add();
            }

        });
    });

    function add() {
        var formData = new FormData($('form')[0]);
        $('#validateBtn').button('loading');
        var specificationNames = new Array();
        var prices = new Array();
        var cash = new Array();
        $('#Specifications .form-group').each(function (i) {
            specificationNames[i] = $(this).children("div").children("div").children(".specificationNames").val();
            prices[i] = $(this).children("div").children("div").children(".prices").val();
            cash[i]=$(this).children("div").children("div").children(".cash").val();
        });
        formData.append('specificationNames', specificationNames);
        formData.append('prices', prices);
        formData.append('cash', cash);
        $.ajax({
            url: website + "/CommodityController/addCommodity",
            type: "post",
            data: formData,
            contentType: false,
            processData: false,
            success: function (data) {
                if (data.code == 200) {
                    //提交动作
                    swal({
                        title: data.msg,
                        type: "success"
                    }, function () {
                        $('#validateBtn').button('reset');
                        window.location.href = "shop.html";
                    });
                } else {
                    swal({
                        title: data.msg,
                        type: "error"
                    }, function () {
                        window.location.href = "shop.html";
                    });
                }
            }
        });
    }

    function update() {
        var formData = new FormData($('form')[0]);
        $('#validateBtn').button('loading');
        var specificationNames = new Array();
        var prices = new Array();
        var cash = new Array();
        $('#Specifications .form-group').each(function (i) {
            specificationNames[i] = $(this).children("div").children("div").children(".specificationNames").val();
            prices[i] = $(this).children("div").children("div").children(".prices").val();
            cash[i]=$(this).children("div").children("div").children(".cash").val();
        });
        formData.append('specificationNames', specificationNames);
        formData.append('prices', prices);
        formData.append('cash', cash);
        $.ajax({
            url: website + "/CommodityController/addCommodity",
            type: "post",
            data: formData,
            contentType: false,
            processData: false,
            success: function (data) {
                if (data.code == 200) {
                    //提交动作
                    swal({
                        title: data.msg,
                        type: "success"
                    }, function () {
                        $('#validateBtn').button('reset');
                        window.location.href = "shop.html";
                    });
                } else {
                    swal({
                        title: data.msg,
                        type: "error"
                    }, function () {
                        window.location.href = "shop.html";
                    });
                }
            }
        })
    }


    // 分类
    function querytype() {
        $.ajax({
            url: website + "/CommodityClassificationController/queryAll1",
            type: "POST",
            processData: false,
            success: function (data) {
                var options = [];
                data.data.forEach(function (obj) {
                    if (obj.id === key) {
                        options.push('<option value="' + obj.id + '" selected>' + obj.classificationName + '</option>');
                    } else {
                        options.push('<option value="' + obj.id + '">' + obj.classificationName + '</option>');
                    }

                })
                $('#commodityClassification').append(options);
            },
        });
    }

    /*个人生活照*/
    function removeimgs(obj) {
        swal({
                title: "您确定要删除吗?",
                text: "确认删除?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认删除",
                closeOnConfirm: false
            },
            function () {
                swal({
                    title: '删除成功',
                    type: "success"
                }, function () {
                    $(obj).remove();
                });
            });
        return false;
    }

    function previewImage(file) {
        if (file.files && file.files[0]) {
            var reader = new FileReader();
            reader.onload = function (evt) {
                $(file).parent().prev().html('<li  onclick="removeimgs(this)" class="weui-uploader__file" style="background-image:url(' + evt.target.result + ')"></li>');
            };
            reader.readAsDataURL(file.files[0]);
        }
    }
</script>

</body>

</html>